<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const s = ['123', '456', '789']
    let iterator = s[Symbol.iterator]()
    // 调用对象的next 方法
    console.log(iterator.next());
    console.log(iterator.next());
    console.log(iterator.next());
    console.log(iterator.next());
    // 迭代器的应用
    const s1 = {
      name: '123',
      status: [
        '12345',
        '123456',
        '1234567',
        '12345678',
      ],
      [Symbol.iterator]() {
        // 索引变量
        let index = 0
        return {
          next: () => {
            if (index < this.status.length) {

              const res = {
                value: this.status[index],
                done: false
              }
              index++
              return res
            } else {
              return {
                value: undefined,
                done: true
              }
            }
          }
        }
      }
    }
    for (let v of s1) {
      console.log(v);

    }
  </script>
</body>

</html>